home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / pc / files / dsp / 56000tar.z / 56000tar / 56000 / stereo / stereo.asm < prev    next >
Assembly Source File  |  1992-04-28  |  5KB  |  229 lines

  1. ;
  2. ; This program, originally available on the Motorola DSP bulletin board,
  3. ; is provided under a DISCLAIMER OF WARRANTY available from Motorola DSP
  4. ; Operation, 6501 William Cannon Drive, West, Austin, Texas  78735-8598.
  5. ;
  6.  
  7.  
  8.  
  9.     page 132,66,3,3,0
  10.  
  11.  
  12.     org    x:$0
  13. input    dsm    2
  14. output    dsm    2
  15. missc    ds    3
  16. storer5 ds    1
  17.  
  18.     org    y:$0
  19. average    ds    2
  20. temp    ds    2
  21. storer6 ds    1
  22. storer7 ds    1
  23. coef    ds    3
  24.  
  25.     org    p:$0
  26.     jmp    $40    
  27.  
  28.     org    p:$0c
  29.     jsr     ioprocess
  30.  
  31.     org    p:$0e
  32.     jsr     ioprocess
  33.  
  34. start    equ    $40
  35. half    equ    .5
  36. alpha    equ    .99
  37. beta    equ    1-alpha
  38. oneos2  equ    .70711
  39. maxcos    equ    2.56   
  40. coefa1    equ    .8803385
  41. coefa2    equ    -.1985987
  42. coefa0    equ    .3175231
  43.  
  44. sqrt    macro
  45.     mpyr    x0,x0,b        y:(r5)+,y0
  46.     mpy    x0,y0,b    b,x1    y:(r5)+,y0
  47.     macr    x1,y0,b        y:(r5)+,y0
  48.     add     y0,b
  49.     endm
  50.  
  51. divide    macro
  52.     and    #$fe,ccr
  53.     rep    #$18
  54.     div    x0,a
  55.     add    x0,a
  56.     move    a0,b
  57.     endm
  58.  
  59.  
  60.  
  61.     org    p:start
  62.     or    #$03,mr
  63.     movep    #$1a00,x:$ffed
  64.     movep    #$3000,x:$ffff
  65.     movep    #$4100,x:$ffec
  66.     movep    #$ba00,x:$ffed
  67.     movep    #$1ff,x:$ffe1
  68.     movep    #$3,x:$ffe2
  69.     move    #coef,r5
  70.     move    #input,r1            ;set r1 to point to
  71.     move    #coefa1,b
  72.     move    #coefa2,a    
  73.     move    b,y:(r5)+
  74.     move    #coefa0,b    
  75.     move    a,y:(r5)+
  76.     move    b,y:(r5)
  77.     move    #1,m0                    ;input
  78.     move    #missc+2,r2            ;set r2 to point to
  79.     move    #2,n2
  80.     move    #input,r0
  81.     move    #output,r3
  82.     move    n2,n1
  83.     move    #0,n6
  84.     move    m0,m3
  85.                         ;bottom of misc.
  86.     move    #average,r4            ;set r4 to point at
  87.                         ;average locations
  88.     move    #temp,r5            ;set r5 to the temporary
  89.     move    n6,y:(r4)+
  90.     move    n6,y:(r4)-
  91.     andi    #$fc,mr
  92.  
  93. loop0    jmp    loop0
  94.  
  95. ioprocess
  96.     movep    x:$ffef,x:(r0)+
  97.     movep    x:(r3)+,x:$ffef
  98.     move     n6,a
  99.     move    r0,b
  100.     cmp    a,b
  101.     jseq    detect
  102.     rti
  103.  
  104.                         ;I and Q locations
  105. detect
  106.     move    x:(r1)+,y0            ;move input into  x0
  107.     move     x:(r1)+n1,x1    y0,y:(r5)+    ;move x0 into temp.
  108.                         ;move q input into x1
  109.                          ;move q into temp
  110.     move    x1,y:(r5)-
  111.     move    #beta,y1            ;move beta into y1 to  
  112.                         ;perform average
  113.                         ;calculation
  114.     mpy    y0,y1,a        #alpha,y0    ;multiply I input by beta
  115.                         ;move alpha(1-beta)
  116.                         ;into y0
  117.     mpy    x1,y1,b        y:(r4)+,x0    ;multiply q input by beta
  118.                         ;move past I average
  119.                         ;xo to continue average
  120.     mac    x0,y0,a        y:(r4)-,x1    ;acuumulate the new
  121.                         ;I average and move
  122.                         ;the old Q average 
  123.                         ;into x1
  124.     mac    x1,y0,b        a,y:(r4)+    ;accumulate the new Q
  125.                         ;average and move new
  126.                         ;I average into memory
  127.     sub    b,a    b,x1    b,y:(r4)-    ;subtract Q from I to
  128.                         ;get carrier value and
  129.                         ;move Q average to mem.
  130.     move    a,x:(r2)-    y:(r5)+,a    ;move carrier into
  131.                         ;memory an move I 
  132.                         ;into a to find bias
  133.     sub    x1,a        #0,b        ;subtract bias from I
  134.                         ;move Q into x0    
  135.     cmp    b,a        y:(r5)-,x0
  136.     jne    start1
  137.     move    (r2)+
  138.     move    a1,x:(r1)-
  139.     move    a1,x:(r1)-n1
  140.     rts
  141. start1    asr    a        a,y:(r5)+    ;Shift I* right and
  142.                         ;store I*
  143.     tfr    x0,a        a,x0        ;transfer a and x0 so
  144.                         ;bias can be subtracted
  145.                         ;from q
  146.     sub    x1,a        #0,r6        ;subtract bias from Q
  147.                         ;move #0 into r6 to
  148.                         ;count the number of
  149.                         ;shift lefts needed
  150.                         ;to make the number be
  151.                         ;between .5<b,1
  152.     asr    a        a,y:(r5)-    ;Divide Q* in half
  153.                         ;store Q* in memory
  154.     mpy    x0,x0,b        a,y0        ;square I*/2
  155.     mac    y0,y0,b            #half,y0    ;add to square Q*/2
  156.                         ;Put .5 into y0 to
  157.                         ;compare for sqrt
  158.     
  159. loop1    cmp    y0,b                ;compare b to .5 to see
  160.                         ;if it is greater than
  161.                         ;.5 for the sqrt
  162.                         ;algorithm
  163.     jge    dosqrt                ;jump if greater than
  164.     asl    b    x:(r6)+,x1        ;if b is less than .5
  165.                         ;then shift b left and 
  166.                         ;increment r6
  167.     jmp    loop1                ;jump to compare again
  168. dosqrt 
  169.     move    #coef,r5
  170.     move    b,x0
  171.     sqrt
  172.     move    r6,x0
  173.     move    #0,a
  174.     cmp    x0,a    #temp,r5
  175.     jeq    around1
  176.     move      #oneos2,y0            ;now multiply the out
  177.                         ;put by 1/sqrt2 for
  178.                         ;every shift left 
  179.     do    x0,enddo1
  180.     move    b,x1                ;move b into x0 to mult.
  181.     mpy    x1,y0,b                ;multiplly by 1/sqrt2
  182. enddo1
  183. around1    move    b,x:(r2)-    y:(r5),a    ;store h and recall I*
  184.                         ;to get ready to divide
  185.                         ;H by I* to ger 1/cos0
  186.     abs    a    #1,r7    
  187.                         ;for the number of shift
  188.                         ;lefts neede for
  189.                         ;dividing H by I
  190. loop2    cmp    a,b        y:(r5),y0    ;So compare I to H
  191.     jlt     dodivide            ;Do the divide if H<I
  192.     asr    b    x:(r7)+,x1        ;If H>I,shift H right
  193.                         ;and increment the
  194.                         ;counter
  195.     jmp    loop2
  196. dodivide
  197.     tfr    b,a        a,x0
  198.     divide
  199.     move    r7,x0
  200.     move    b,x:(r2)+n2            ;store 1/cos0
  201.     move    x:(r2),a                   ;move carrier into a and
  202.                         ;store 1/cos0 in x1
  203.     rep    x0 
  204.     asr     a                ;shift the carrier right
  205.                         ;as many times as the
  206.                         ;H was shifted for the
  207.                         ;divide + one for the 
  208.                         ;shift right of I and Q
  209.                         ;before the sum of
  210.                         ;squares 
  211.                         ;save the new carrier
  212.     move    b,x1     y:(r5)+,y1
  213.                         ;back to memory and 
  214.                         ;move I* back into x0
  215.     mpy    x1,y1,b    a,x:(r2) y:(r5)-,y0    ;multiply I* by 1/cos0
  216.                         ;and move Q* into y0
  217.     mpy    x1,y0,a        a,y1        ;multiply Q* by 1/cos0
  218.                         ;and move a into x0
  219.     sub    y1,b                ;subtract the carrrier
  220.                         ;from I and store (L-R)
  221.     add    b,a        a,x0        ;left
  222.     sub    x0,b    
  223.     asl     a
  224.     asl    a
  225.     asl    b
  226.         asl     b    a,x:(r1)-    ;right
  227.     move    b,x:(r1)-n1
  228.     rts
  229.